package com.party.course.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.party.common.annotation.Log;
import com.party.common.core.controller.BaseController;
import com.party.common.core.domain.AjaxResult;
import com.party.common.enums.BusinessType;
import com.party.common.utils.SecurityUtils;
import com.party.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.party.course.domain.StudentChangeInfo;
import com.party.course.service.IStudentChangeInfoService;
import com.party.common.core.page.TableDataInfo;

/**
 * 学员课程变动Controller
 *
 * @author ruoyi
 * @date 2025-05-29
 */
@RestController
@RequestMapping("/course/StudentChange")
public class StudentChangeInfoController extends BaseController {
    @Autowired
    private IStudentChangeInfoService studentChangeInfoService;

    /**
     * 查询学员课程变动列表
     */
//@RequiresPermissions("course:StudentChange:list")
    @GetMapping("/list")
    public TableDataInfo list(StudentChangeInfo studentChangeInfo) {
        startPage();
        String username = SecurityUtils.getLoginUser().getUsername();
        if (!"admin".equals(username)) {
            String phonenumber = SecurityUtils.getLoginUser().getUser().getPhonenumber();
            studentChangeInfo.setTjPersonPhone(phonenumber);
        }

        List<StudentChangeInfo> list = studentChangeInfoService.findList(studentChangeInfo);
        return getDataTable(list);
    }

    /**
     * 导出学员课程变动列表
     */
    //@RequiresPermissions("course:StudentChange:export")
    @Log(title = "学员课程变动", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StudentChangeInfo studentChangeInfo) {
        List<StudentChangeInfo> list = studentChangeInfoService.findList(studentChangeInfo);
        ExcelUtil<StudentChangeInfo> util = new ExcelUtil<StudentChangeInfo>(StudentChangeInfo.class);
        util.exportExcel(response, list, "学员课程变动数据");
    }

    /**
     * 获取学员课程变动详细信息
     */
    //@RequiresPermissions("course:StudentChange:query")
    @GetMapping(value = "/view/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(studentChangeInfoService.view(id));
    }

    /**
     * 新增学员课程变动
     */
    //@RequiresPermissions("course:StudentChange:add")
    @Log(title = "学员课程变动", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody StudentChangeInfo studentChangeInfo) {
        return toAjax(studentChangeInfoService.add(studentChangeInfo));
    }

    /**
     * 修改学员课程变动
     */
    //@RequiresPermissions("course:StudentChange:edit")
    @Log(title = "学员课程变动", businessType = BusinessType.UPDATE)
    @PutMapping("/update")
    public AjaxResult edit(@RequestBody StudentChangeInfo studentChangeInfo) {
        return toAjax(studentChangeInfoService.updateEntity(studentChangeInfo));
    }

    /**
     * 删除学员课程变动
     */
    //@RequiresPermissions("course:StudentChange:remove")
    @Log(title = "学员课程变动", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(studentChangeInfoService.deleteIds(Arrays.asList(ids)));
    }
}
